﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MyGUI.WcfFlightRoutingService;
using MyGUI.Properties;

namespace MyGUI
{
    public partial class ShowTravel : Form
    {
        List<Airport> solutionpath;
        public ShowTravel(List<Airport> dijkstraList)
        {
            solutionpath = dijkstraList;
            InitializeComponent();

           // showit();
        }

        //public void showit()
        //{


        //    string SourceAirport = solutionpath.Last<Airport>().Name;
        //    double totalprice = solutionpath.Last<Airport>().Price;
        //    int    totaltraveltime = solutionpath.Last<Airport>().Dist;
        //    string DepatureTime = solutionpath.Last<Airport>().AdjFlight.Timeofdeparture.ToString();

        //    string DestAirport = solutionpath.First<Airport>().Name;
        //    string ArrivalTime = solutionpath.First<Airport>().AdjFlight.Timeofarrival;

        //    int numofstops = 0;
        //    if (solutionpath.Count > 2)
        //        numofstops = solutionpath.Count - 2;

        //    //foreach (Airport a in solutionpath)
        //    //{
        //    //    if (a == solutionpath.Last<Airport>()) // Source airport equal to last in list 
        //    //    {
        //    //        SourceAirport = a.Name.ToString();
        //    //        totalprice = a.Price;
        //    //        totaltraveltime = a.Dist;
        //    //    }
        //    //    else
        //    //    {
        //    //        if (a == solutionpath.First<Airport>()) // Destination airport equal to first in list
        //    //        {
        //    //            DestAirport = a.Name.ToString();
        //    //            ArrivalTime = a.AdjFlight.Timeofarrival.ToString();
        //    //        }

        //    //        if (a.PreviousVertex.IdAirport == solutionpath.Last<Airport>().IdAirport)
        //    //        // Flight info is stored in the first airport node after source airport.
        //    //        {
        //    //            DepatureTime = a.AdjFlight.Timeofdeparture.ToString();
        //    //        }
        //    //    }
        //    //}

        //    MessageBox.Show("Source Airport: " + SourceAirport + ", " + "Destination Airport: " + DestAirport + ", " + "Departure Time: " +
        //        DepatureTime + ", "  + "Arrival Time: " + ArrivalTime + ", " + "Total Price: " + totalprice.ToString() + " DDK, " 
        //        + "Total Travel Time: " + totaltraveltime.ToString()+"min., " + "Total Num Of Stops: " + numofstops.ToString());

        //}

        private void travelsListView_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void ShowTravel_Load(object sender, EventArgs e)
        {
            try
            {
                string SourceAirport = solutionpath.Last<Airport>().Name;
                double totalprice = solutionpath.Last<Airport>().Price;
                int totaltraveltime = solutionpath.First<Airport>().Dist;
                string DepatureTime = solutionpath.Last<Airport>().AdjFlight.Timeofdeparture.ToString();

                string DestAirport = solutionpath.First<Airport>().Name;
                string ArrivalTime = solutionpath.First<Airport>().AdjFlight.Timeofarrival;

                int numofstops = 0;
                if (solutionpath.Count > 2)
                    numofstops = solutionpath.Count - 2;

                //foreach (Airport a in solutionpath)
                //{
                //    if (a == solutionpath.Last<Airport>()) // Source airport equal to last in list 
                //    {
                //        SourceAirport = a.Name.ToString();
                //        totalprice = a.Price;
                //        totaltraveltime = a.Dist;
                //    }
                //    else
                //    {
                //        if (a == solutionpath.First<Airport>()) // Destination airport equal to first in list
                //        {
                //            DestAirport = a.Name.ToString();
                //            ArrivalTime = a.AdjFlight.Timeofarrival.ToString();
                //        }

                //        if (a.PreviousVertex.IdAirport == solutionpath.Last<Airport>().IdAirport)
                //        // Flight info is stored in the first airport node after source airport.
                //        {
                //            DepatureTime = a.AdjFlight.Timeofdeparture.ToString();
                //        }
                //    }
                //}
                ListViewItem listviewObj = new ListViewItem(SourceAirport);
                listviewObj.SubItems.Add(DestAirport);
                listviewObj.SubItems.Add(DepatureTime);
                listviewObj.SubItems.Add(ArrivalTime);
                listviewObj.SubItems.Add(totaltraveltime.ToString());
                listviewObj.SubItems.Add(totalprice.ToString());
                listviewObj.SubItems.Add(numofstops.ToString());
                travelsListView.Items.Add(listviewObj);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            //MessageBox.Show("Source Airport: " + SourceAirport + ", " + "Destination Airport: " + DestAirport + ", " + "Departure Time: " +
            //    DepatureTime + ", " + "Arrival Time: " + ArrivalTime + ", " + "Total Price: " + totalprice.ToString() + " DDK, "
            //    + "Total Travel Time: " + totaltraveltime.ToString() + "min., " + "Total Num Of Stops: " + numofstops.ToString());



        }

            
        }

        

    }

